﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net.Sockets;

namespace MasterServer {
	public abstract class Protocol {
		internal StreamReader streamReader { get; set; }
		internal StreamWriter streamWriter { get; set; }
		internal NetworkStream networkStream { get; set; }
		internal bool Send(String message) {
			try {
				Console.WriteLine("Wysylam: " + message);
				streamWriter.WriteLine(message);
				streamWriter.Flush();
				return true;
			} catch (Exception e) {
				Console.Write(e.Message);
				return false;
			}
		}
		internal string Receive() {
			string s = streamReader.ReadLine();
			Console.WriteLine("Odebralem: " + s);
			return s;
		}

		internal virtual void Disconnect() {
			this.streamReader.Close();
			this.streamWriter.Close();
			this.networkStream.Close();
		}
	}
}
